/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       drag_creature.cpp

	$Header: /game/drag_creature.cpp $

	$NoKeywords: $

 ************************************************************************/
// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "drag_creature.h"

#include "bitmap_group.h"
#include "bitmap_group_cache.h"
#include "bitmap_layer_cache_window.h"
#include "creature_array_window.h"
#include "creature_traits.h"
#include "hero.h"

extern t_bitmap_group_cache g_creature_rings;
extern t_bitmap_group_cache g_creature_portraits;

// --------------------------------------------------------
// drag and drop object for creatures
// --------------------------------------------------------
t_drag_creature::t_drag_creature( t_creature_stack* creature, 
								  t_creature_array_window* source_window,
		                          int source_slot, int transfer_charge,
								  bool use_split_dialog )
{
	m_data = creature;
	m_source_window = source_window;
	m_source_slot = source_slot;
	m_use_split_dialog = use_split_dialog;
	m_transfer_charge = transfer_charge;

	m_rings = g_creature_rings.get();

	t_window*             window;
	t_screen_point        portrait_offset = m_rings->find( "portrait" )->get_rect().top_left();
	t_bitmap_layer const* ring            = m_rings->find( "drag_border" );
	t_screen_rect         rect = ring->get_rect();

	set_hot_spot( t_screen_point( rect.right / 2, rect.bottom / 2 ) );
	m_portrait = m_data->get_portrait();
	window = new t_bitmap_layer_cache_window( m_portrait, t_screen_point(0,0), this );
	window = new t_bitmap_layer_window( ring, -portrait_offset, this );
}

// --------------------------------------------------------
// drag and drop object for creatures
// --------------------------------------------------------
t_drag_creature::~t_drag_creature()
{
	// undo removal of creature from source
	if (m_source_window != 0 && !m_use_split_dialog)
	{
		m_source_window->add( m_data, m_source_slot, 0, m_transfer_charge );
		m_source_window->update();
	}
}

// --------------------------------------------------------
// drag and drop object for creatures
// --------------------------------------------------------
void t_drag_creature::accepted( t_window* window )
{
	m_source_window = 0;
	m_data = new t_creature_stack;

	close();
}

// --------------------------------------------------------
// swap data
// --------------------------------------------------------
void t_drag_creature::swap( t_creature_stack_ptr& arg, int charge_transfer )
{
	t_creature_stack_ptr temp = arg;

	arg = m_data;
	m_data = temp;
	m_transfer_charge = charge_transfer;
	// check if we were trying to split
	if (m_use_split_dialog)
	{
		m_source_window->clear_slot( m_source_slot );
		m_use_split_dialog = false;
	}
}

